package com.treeHole.treeHoleServer.controller;


import com.treeHole.treeHoleServer.pojo.RequestDataDTO.GetListGeneralDTO;
import com.treeHole.treeHoleServer.pojo.Result;
import com.treeHole.treeHoleServer.pojo.ResultDataDTO.ResultCommentDTO;
import com.treeHole.treeHoleServer.pojo.ResultDataDTO.ResultPostDTO;
import com.treeHole.treeHoleServer.service.CommentService;
import com.treeHole.treeHoleServer.service.PostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 用于处理用户主页的请求，包括获取用户发布的帖子、用户收藏的帖子、用户发布的评论
 */
@Slf4j
@RestController
@RequestMapping("/homepage")
public class HomepageController {

    @Autowired
    CommentService commentService;

    @Autowired
    PostService postService;




    @PostMapping("/posts")
    public Result getUserPosts(@RequestBody GetListGeneralDTO getListGeneralDTO) {
        List<ResultPostDTO> resultList=postService.getUserPersonalPost(getListGeneralDTO.getUserId(),getListGeneralDTO.getPage());
        log.info("收到获取用户个人帖子请求,getListGeneralDTO:{}",getListGeneralDTO);
        return Result.success(resultList);
    }

    @PostMapping("/favorite")
    public Result getUserFavorites(@RequestBody GetListGeneralDTO getListGeneralDTO) {
        List<ResultPostDTO> resultList=postService.getUserFavoritePost(getListGeneralDTO.getUserId(),getListGeneralDTO.getPage());
        log.info("收到获取用户收藏帖子请求,getListGeneralDTO:{}",getListGeneralDTO);
        return Result.success(resultList);
    }

    @PostMapping("/comment")
    public Result getUserComments(@RequestBody GetListGeneralDTO getListGeneralDTO) {
        log.info("收到请求个人评论列表的请求,用户id:{},请求页:{}",getListGeneralDTO.getUserId(),getListGeneralDTO.getPage());
        List<ResultCommentDTO> resultCommentDTOList=commentService.getUserComments(getListGeneralDTO.getUserId(),getListGeneralDTO.getPage());
        log.info("查询到{}条评论",resultCommentDTOList.size());
        return Result.success(resultCommentDTOList);
    }

}
